package com.wetao.module_user.fragment;

import android.os.Bundle;
import android.view.View;

import com.wetao.lib_common.base.BaseLazyFragment;
import com.wetao.lib_common.utils.BaseEvent;
import com.wetao.lib_common.view.OnMultiClickListener;
import com.wetao.module_user.R;
import com.wetao.module_user.contract.UserSettingFragmentCon;
import com.wetao.module_user.presenter.UserSettingFragmentPre;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class UserSettingFragment extends BaseLazyFragment<UserSettingFragmentCon.View, UserSettingFragmentPre> implements
        UserSettingFragmentCon.View {


    public static UserSettingFragment newInstance(/*String className, Integer classId*/) {
        Bundle args = new Bundle();
        /*args.putString("className", className);
        args.putInt("classId", null == classId ? -1 : classId);*/

        UserSettingFragment fragment = new UserSettingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.user_fragment_setting;
    }

    @Override
    public UserSettingFragmentPre createPresenter() {
        return new UserSettingFragmentPre(mContext);
    }

    @Override
    public UserSettingFragmentCon.View createView() {
        return this;
    }

    @Override
    public void init(View rootView) {
        Bundle bundle = null;
        if ((bundle = getArguments()) != null) {
            String className = bundle.getString("className");
            /*if(!TextUtils.isEmpty(className)) {
                tvClassAdmin.setText(className);
            }*/
            int classId = bundle.getInt("classId");
        }

        rootView.findViewById(R.id.tv_pwd_arrow).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
                if(null != onListenClick) {
                    onListenClick.onListenPwdClick();
                }
            }
        });
        rootView.findViewById(R.id.bt_exit).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
                if(null != onListenClick) {
                    onListenClick.onListenExitClick();
                }
            }
        });
    }

    @Override
    public void onFragmentFirst() {
        super.onFragmentFirst();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public void onFragmentInVisible() {
        super.onFragmentInVisible();
    }

    @Override
    public void onFragmentVisble() {
        super.onFragmentVisble();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN) //在ui线程执行
    public void onEventReceived(BaseEvent event) {
        if (event.getCode() == 1) {//退出登录  刷新列表

        }
    }

    public interface OnListenClick{
        void onListenPwdClick();
        void onListenExitClick();
    }
    OnListenClick onListenClick;

    public void setOnListenClick(OnListenClick onListenClick) {
        this.onListenClick = onListenClick;
    }
}
